home *** CD-ROM | disk | FTP | other *** search
/ T&A 2 the Maxx 3 / T and A 2 The Maxx Number 3.iso / viewers / unixview / xgiftar.z / xgiftar / imagetypes.c < prev    next >
C/C++ Source or Header  |  1991-05-20  |  2KB  |  101 lines

  1. /* imagetypes.c:
  2.  *
  3.  * this contains things which reference the global ImageTypes array
  4.  *
  5.  * jim frost 09.27.89
  6.  *
  7.  * Copyright 1989, 1991 Jim Frost.
  8.  * See included file "copyright.h" for complete copyright information.
  9.  */
  10.  
  11. #include "copyright.h"
  12. #include "image.h"
  13. #include "imagetypes.h"
  14. #include <errno.h>
  15.  
  16. /* SUPPRESS 560 */
  17.  
  18. extern int errno;
  19.  
  20. /* load a named image
  21.  */
  22.  
  23. Image *loadImage(name, verbose)
  24.      char         *name;
  25.      unsigned int  verbose;
  26. { char   fullname[BUFSIZ];
  27.   Image *image;
  28.   int    a;
  29.  
  30.   if (findImage(name, fullname) < 0) {
  31.     if (errno == ENOENT)
  32.       printf("%s: image not found\n", name);
  33.     else
  34.       perror(fullname);
  35.     return(NULL);
  36.   }
  37.   for (a= 0; ImageTypes[a].loader; a++)
  38.     if (image= ImageTypes[a].loader(fullname, name, verbose)) {
  39.       zreset(NULL);
  40.       return(image);
  41.     }
  42.   printf("%s: unknown or unsupported image type\n", fullname);
  43.   zreset(NULL);
  44.   return(NULL);
  45. }
  46.  
  47. /* identify what kind of image a named image is
  48.  */
  49.  
  50. void identifyImage(name)
  51.      char *name;
  52. { char fullname[BUFSIZ];
  53.   int  a;
  54.  
  55.   if (findImage(name, fullname) < 0) {
  56.     if (errno == ENOENT)
  57.       printf("%s: image not found\n", name);
  58.     else
  59.       perror(fullname);
  60.     return;
  61.   }
  62.   for (a= 0; ImageTypes[a].identifier; a++) {
  63.     if (ImageTypes[a].identifier(fullname, name)) {
  64.       zreset(NULL);
  65.       return;
  66.     }
  67. }
  68.   zreset(NULL);
  69.   printf("%s: unknown or unsupported image type\n", fullname);
  70. }
  71.  
  72. /* tell user what image types we support
  73.  */
  74.  
  75. void supportedImageTypes()
  76. { int a;
  77.  
  78.   printf("Image types supported:\n");
  79.   for (a= 0; ImageTypes[a].name; a++)
  80.     printf("  %s\n", ImageTypes[a].name);
  81. }
  82.  
  83. void goodImage(image, func)
  84.      Image *image;
  85.      char  *func;
  86. {
  87.   if (!image) {
  88.     printf("%s: nil image\n", func);
  89.     exit(0);
  90.   }
  91.   switch (image->type) {
  92.   case IBITMAP:
  93.   case IRGB:
  94.   case ITRUE:
  95.     break;
  96.   default:
  97.     printf("%s: bad destination image\n", func);
  98.     exit(0);
  99.   }
  100. }
  101.